package com.kc.web.controller.business;

import com.kc.business.domain.vo.KcUserWalletWithdrawApplyVo;
import com.kc.business.service.KcUserWalletWithdrawApplyService;
import com.kc.common.annotation.RepeatSubmit;
import com.kc.common.core.controller.BaseController;
import com.kc.common.core.domain.AjaxResult;
import com.kc.common.core.domain.model.LoginUser;
import com.kc.common.core.page.TableDataInfo;
import com.kc.common.utils.ServletUtils;
import com.kc.framework.web.service.TokenService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * FileName:   KcUserWalletWithdrawApplyController
 * Author:     TP
 * Date:       12/21/20 11:52 AM
 * Description:
 */
@RestController
@RequestMapping("/userWalletWithdrawApply")
public class KcUserWalletWithdrawApplyController extends BaseController {

    @Resource
    private KcUserWalletWithdrawApplyService userWalletWithdrawApplyService;

    @Resource
    private TokenService tokenService;

    /**
     * 获取列表
     */
    @PreAuthorize("@ss.hasPermi('business:userWalletWithdrawApply:list')")
    @GetMapping("/list")
    public TableDataInfo getList(KcUserWalletWithdrawApplyVo applyVo) {
        startPage();
        List<KcUserWalletWithdrawApplyVo> list = userWalletWithdrawApplyService.getList(applyVo);
        return getDataTable(list);
    }

    /**
     * 审核
     */
    @PreAuthorize("@ss.hasPermi('business:userWalletWithdrawApply:audit')")
    @PutMapping("/audit")
    @RepeatSubmit
    public AjaxResult audit(@RequestBody KcUserWalletWithdrawApplyVo applyVo) {
        if (applyVo == null) {
            return AjaxResult.error("参数错误");
        }
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        applyVo.setUpdateTime(LocalDateTime.now());
        applyVo.setAuditUserName(loginUser.getUsername());
        applyVo.setAuditUserId(loginUser.getUser().getUserId().intValue());
        return userWalletWithdrawApplyService.audit(applyVo);
    }

}